{% extends "base.html"%}
{% load commonFilters %}
{% load i18n %}

{% comment %}
copyright (c) 2009, paketka@gmail.com et. al
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

	* Redistributions of source code must retain the above copyright notice,
	  this list of conditions and the following disclaimer.

	* Redistributions in binary form must reproduce the above copyright notice,
	  this list of conditions and the following disclaimer in the documentation
	  and/or other materials provided with the distribution.

	* Neither the name of the <ORGANIZATION> nor the names of its contributors
	  may be used to endorse or promote products derived from this software
 	  without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
{% endcomment %}

{% block keywords %}
{{ group.name }}, {% ifequal group.type "KLUB" %} {{ group.getPartyName }} {% endifequal %},
období {{ group.term.getStart }} - {{ group.term.getEnd }}, volební období, přehled za období,
srovnat s ostatními
{% endblock %}
{% block css-links %}
	<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}/css/ui.jqgrid.css" />
{% endblock %}

{% block js-links %}
	<script type="text/javascript" src="{{ MEDIA_URL }}/js/jquery.scrollTo-min.js"></script>
	<script type="text/javascript" src="{{ MEDIA_URL }}/js/js/jqModal.js"></script>
	<script type="text/javascript" src="{{ MEDIA_URL }}/js/js/jqDnR.js"></script>
	<script type="text/javascript" src="{{ MEDIA_URL }}/js/js/jquery.jqGrid.js"></script>
{% endblock %}

{% block javascript-head %}
{{ block.super }}

var loyalChartsArray = [
{% for groupType, groups in groupsByType.items %}
	'{% for g in groups %}\
		{% if forloop.first %}\
			<option value="">{% trans "Vyberte skupinu" %}</option>\
		{% endif %}\
		{% ifequal g.type groupType %}\
			<option value="{{ g.id }}"> {{ g.name|truncatewords:4 }} </option>\
		{% endifequal %}\
	{% endfor %}'
	{% if not forloop.last %}
				,
	{% endif %}
{% endfor %}
];

var indexDict = {
	'groupTypeDay' : 0,
	'groupTypeTerm' : 0,
	'groupNamesTerm' : 0,
	'groupNamesDay' : 0
};

var linkParams = [];

function createGrid(tableId, pagerId, url, caption)
{
	$(tableId).jqGrid({
				url: url,
				datatype: 'json',
				colNames: [	"{% trans "Číslo hlasování" %}",
							"{% trans "Název hlasování" %}",
							"{% trans "Výsledek" %}"
					],
				colModel :[
					{ name: "pollNo", index: "pollNo", width: 80, jsonmap: "pollNo", sortable: false },
					{ name: "title", index: "title", width: 200, jsonmap: "title", sortable: false },
					{ name: "result", index: "result", width: 120, jsonmap:"result", sortable: false }
				], 
				pager: $(pagerId),
				jsonReader: {
					root: "rows",
					id: "pk",
					page: "page",
					total: "total",
					records: "records",
					repeatitems: false
				},
				sortname:"start",
				sortorder:"desc",
				rowNum:10,
				rowList:[10,15,20],
				viewrecords:true,
				caption: caption,
				width:640,
				toolbar: [true,'top']
	});
}

{% comment %}
function handles group change type events for both
term and date pies.
{% endcomment %}

function updateCtrlLink()
{
	var baseUrl = $('.ctrl-link').attr('href');
	var tmpUrl = '';

	for (key in linkParams) {
		tmpUrl += key + '=' + linkParams[key] + '&';
	}

	if (tmpUrl != '') {
		baseUrl = baseUrl.replace(/\?.*$/g,'');
		baseUrl += '?' + tmpUrl.replace(/&$/g, '');
		$('.ctrl-link').attr('href', baseUrl);
	}
}

function groupTypeChanged(elemId)
{
	selector = '#' + elemId;
	index = $(selector)[0].selectedIndex;
	indexDict[elemId] = index;
	if (elemId == 'groupTypeDay') {
		linkParams['peerGroupTypeIndex'] = index;
		$('#groupNamesDay').html(loyalChartsArray[index]);
	}
	else if(elemId == 'groupTypeTerm') {
		linkParams['peerTermGroupTypeIndex'] = index;
		$('#groupNamesTerm').html(loyalChartsArray[index]);
	}
}

function groupNameChanged(elemId)
{
	selector = '#' + elemId;
	index = $(selector)[0].selectedIndex;
	indexDict[elemId] = index;
	groupId = '{{ group.id }}';
	otherGroupId = $(selector)[0].options[index].value;
	
	if (elemId == 'groupNamesDay') {
		{% url json.views.get_day_accordance_pie_chart_for_group "0" "0" 1970 1 1  as baseUrl %}
		dateUrl = '{{ baseUrl }}'.replace(/\/\d+\/\d+\/\d{4}\/\d{1,2}\/\d{1,2}\//g,'');
		dateUrl += '/' + groupId + '/' + otherGroupId + '/' + currentDate;
		$("#loyalChartDayGroup").html("<img src=\"{{ MEDIA_URL }}/images/wait.gif\"/>");
		$("#partyPieChartDay").html('');
		linkParams['peerGroupIndex'] = index;
		$.ajax({
				url : dateUrl,
				async : true,
				dataType : 'json',
				success : function(data) {
					$("#partyPieChartDay").html(data.partyPie);
					$("#loyalChartDayGroup").html(data.loyalChart);
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					$("#partyPieChartDay").html('<img src="{{ MEDIA_URL }}/images/error.gif"/>');
					$("#loyalChartDayGroup").html('<img src="{{ MEDIA_URL }}/images/error.gif"/>');
				}
		});

		updateCtrlLink();
	}
	else if (elemId == 'groupNamesTerm') {
		{% url json.views.get_term_accordance_pie_chart_for_group "0" "0" 0  as baseUrl %}
		dateUrl = '{{ baseUrl }}'.replace(/\/\d+\/\d+\/\d+\//g,'');
		dateUrl += '/' + groupId + '/' + otherGroupId + '/' + '{{ term.termId }}' + '/';
		$("#loyalChartGroupTerm").html("<img src=\"{{ MEDIA_URL }}/images/wait.gif\"/>");
		$("#partyPieChartTerm").html('');
		linkParams['peerTermGroupIndex'] = index;
		$.ajax({
				url : dateUrl,
				async : true,
				dataType : 'json',
				success : function(data) {
					$("#partyPieChartTerm").html(data.partyPie);
					$("#loyalChartGroupTerm").html(data.loyalChart);
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					$("#partyPieChartTerm").html('<img src="{{ MEDIA_URL }}/images/error.gif"/>');
					$("#loyalChartGroupTerm").html('<img src="{{ MEDIA_URL }}/images/error.gif"/>');
				}
		});

		updateCtrlLink();
	}
	else 
		return;
}

{% if prevDate %}
	var prevDate = '{{ prevDate|date:"Y/m/d/" }}';
{% else %}
	var prevDate = null;
{% endif %}

{% if nextDate %}
	var nextDate = '{{ nextDate|date:"Y/m/d/" }}';
{% else %}
	var nextDate = null;
{% endif %}

{% if currentDate %}
	var currentDate = '{{ currentDate|date:"Y/m/d/" }}';
{% else %}
	var currentDate = null;
{% endif %}

var filterEnabled = false;

function getUrl(urlStr)
{% comment %}
it checks if 'Proceduralni hlasovani' polls should be removed from grids,
if so, it then appends an option ?filterProcedural=1 to url.
{% endcomment %}
{
	var retVal = "";

	if (filterEnabled)
		retVal = urlStr + '?filterProcedural=1';
	else
		retVal = urlStr.replace(/\?filterProcedural=1/g,'');

	return retVal
}

function filterProcedural(id)
{% comment %}
This is callback, that handles checkbox change events
{% endcomment %}
{
	if (filterEnabled) {
		filterEnabled = false;
	}
	else {
		filterEnabled = true;
	}

	grids = [];
	grids[0] = '#aye';
	grids[1] = '#nay';
	grids[2] = '#refrain';
	grids[3] = '#absences';

	{% comment %}
	We are going to retrieve Data URL for each particular grid
	{% endcomment %}
	for (i in grids) {
		$(grids[i]).setGridParam({
			url : getUrl(	$(grids[i]).getGridParam('url'))
		}).trigger("reloadGrid");
	}
}

function switchDate(dateUrl, date, updateMeetingPicker)
{
	{% comment %}
	dateUrl contains AJAX URL to query for a new pair of previous date and
	next date.
	
	the date is date we are switching to.

	{% endcomment %}

	$("#pollDate").text(date.replace(/\//g, ' '));
	$("#groupDayStatChart").html("<img src=\"{{ MEDIA_URL }}/images/wait.gif\"/>");
	{% comment %}
	This looks a bit strange at first glance, but it's fairly obvious.
	We need to get AJAX URL for data grids to fetch new data. To get these
	URLs we need to:
		get URL json view for particular data, we are using currentDate,
		to get such URL

		once we have the json view URL we need to adjust it for desired day,
		we strip the date parameters i.e. the URL below
			/json/blaBla/josef_novak/2008/7/12/
		will become
			/json/blaBla/josef_novak/

		then we append the desired date parameter to it.
	{% endcomment %}
	{% url json.views.get_group_aye group.slug currentDate.year currentDate.month currentDate.day as gridBaseUrl %}
	var gridUrl = '{{ gridBaseUrl }}'.replace(/\/\d{4}\/\d{1,2}\/\d{1,2}\//g,'');
	$("#aye").setGridParam({ url: gridUrl + '/' + date }).trigger("reloadGrid");

	{% url json.views.get_group_nay group.slug currentDate.year currentDate.month currentDate.day as gridBaseUrl %}
	var gridUrl = '{{ gridBaseUrl }}'.replace(/\/\d{4}\/\d{1,2}\/\d{1,2}\//g,'');
	$("#nay").setGridParam({ url: gridUrl + '/' + date }).trigger("reloadGrid");

	{% url json.views.get_group_refrains group.slug currentDate.year currentDate.month currentDate.day as gridBaseUrl %}
	var gridUrl = '{{ gridBaseUrl }}'.replace(/\/\d{4}\/\d{1,2}\/\d{1,2}\//g,'');
	$("#refrain").setGridParam({ url: gridUrl + '/' + date }).trigger("reloadGrid");

	{% url json.views.get_group_absences group.slug currentDate.year currentDate.month currentDate.day as gridBaseUrl %}
	var gridUrl = '{{ gridBaseUrl }}'.replace(/\/\d{4}\/\d{1,2}\/\d{1,2}\//g,'');
	$("#absences").setGridParam({ url: gridUrl + '/' + date }).trigger("reloadGrid");

	if (updateMeetingPicker) {
		var dateParts = date.split('/');
		var d = new Date(	parseInt(dateParts[0]),
							parseInt(dateParts[1]) - 1,	/* January is month 0 */
							parseInt(dateParts[2])
						);
		$("#meetingPicker").datepicker('setDate', d);
	}

	var baseUrl = $('.ctrl-link').attr('href').replace(/\/\d{4}\/\d{1,2}\/\d{1,2}\//g,'');
	$('.ctrl-link').attr('href', baseUrl + '/' + date);
	updateCtrlLink();

	{% comment %}
	We need to reset loyal day charts
	{% endcomment %}
	indexDict['groupNamesTerm'] = 0;
	indexDict['groupTypeDay'] = 0;
	$('#groupNamesDay').html(loyalChartsArray[0]);
	$('#groupNamesDay')[0].selectedIndex = 0;
	$('#groupTypeDay')[0].selectedIndex = 0;
	$('#loyalChartDayGroup').html('');
	$("#partyPieChartDay").html('');

	$.ajax({
			url : dateUrl,
			async : true,
			dataType : 'json',
			success : function(data) {
					prevDate = data.prevDate;
					nextDate = data.nextDate;
					currentDate = date;

					$("#totalDayPolls").text(data.totalDayPolls);
					$("#acceptedProposals").text(data.acceptedProposals);
					$("#refusedProposals").text(data.refusedProposals);
					$("#groupAbsences").text(data.groupAbsences);				
					$("#groupAye").text(data.groupAye);
					$("#groupNay").text(data.groupNay);
					$("#groupRefrains").text(data.groupRefrains);
					$("#groupDayStatChart").html(data.groupDayStatChart);

					if (nextDate == null) {
						$("#nextDay").hide();
					}
					else {
						$("#nextDate").text(nextDate.replace(/\//g, ' '));
						$("#nextDay").show();
					}

					if (prevDate == null) {
						$("#prevDay").hide();
					}
					else {
						$("#prevDate").text(prevDate.replace(/\//g, ' '));
						$("#prevDay").show();
					}
					
					{% comment %}
					 We need to reset pies for particular day. We simply do:
					 setting index to the second chart url,
					 pretending the 'prev' button was pressed -> index will move
					 to reference the first position.
					{% endcomment %}
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
					$("#groupDayStatChart").html('<img src="{{ MEDIA_URL }}/images/error.gif"/>');
			}
	});
}
function meetingPickerSelect(dateText)
{
	$.scrollTo('#pollDate', 800);
	{% url json.views.get_date_data_group_json group.slug currentDate.year currentDate.month currentDate.day as baseUrl %}
	var baseUrl = '{{ baseUrl }}'.replace(/\/\d{4}\/\d{1,2}\/\d{1,2}\//g,'');
	switchDate(baseUrl + '/' + dateText, dateText, false);
}

$(document).ready(function(){
	$("#mp-list").jqGrid({
				url:'{% url json.views.group_members_json group.slug %}',
				datatype: 'json',
				colNames: [	"{% trans "Jméno" %}",
							"{% trans "Příjmení" %}",
							"{% trans "Funkce" %}",
							"{% trans "Posl. klub" %}",
							"{% trans "Věk" %}",
							"{% trans "Volební obvod" %}",
							"{% trans "Nepřítomnost [%]" %}",
							"{% trans "Od" %}",
							"{% trans "Do" %}",
							"{% trans "Dnů ve funkci" %}"
					],
				colModel :[
					{ name: "name", index: "person__name", width: 120, jsonmap: "name", sortable: true },
					{ name: "surname", index: "person__surname", width:120, jsonmap:"surname", sortable: true },
					{ name: "post", index: "post", width:80, jsonmap:"post", align:"center", sortable: true },
					{ name: "party", index: "group__name", width: "70", align: "center", jsonmap:"party", sortable: true },
					{ name: "age", index: "person__birthDate", width: "30", align: "center", jsonmap:"age", sortable: true },
					{ name: "division", index: "division", width: "100", align: "center", jsonmap:"divName", sortable: true },
					{ name: "absences", index: "absences", width: 70, align: "center", jsonmap: "absences", sortable: true },
					{ name: "start", index: "start", width: 70, align: "center", jsonmap: "start", sortable: true },
					{ name: "end", index: "start", width: 70, align: "center", jsonmap: "end", sortable: true },
					{ name: "days", index: "days", width: 70, align: "center", jsonmap: "days", sortable: true }
				], 
				pager: $('#mp-pager'),
				jsonReader: {
					root: "rows",
					id: "pk",
					page: "page",
					total: "total",
					records: "records",
					repeatitems: false
				},
				sortname:"person__surname",
				sortorder:"asc",
				rowNum:10,
				rowList:[10,15,20],
				viewrecords:true,
				imgpath:"{{ MEDIA_URL }}/css/jqgrid/themes/basic/images",
				caption:"{{ group.name }} {{ term.getStart }} - {{ term.getEnd }}",
				width:780,
				toolbar: [true,'top']
	});
	$("#t_mp-list").filterGrid("#mp-list", {
				gridModel: false,
				gridToolBar: false,
				filterModel: [ {
					label: '',
					name: 'filter__exp',
					stype: 'text',
					defval: ''
				} ],
				autosearch: true,
				searchButton: '{% trans "Hledej" %}',
				enableSearch: true
			}
		);

	createGrid(
		"#aye",
		"#aye-pager",
		"{% url json.views.get_group_aye group.slug currentDate.year currentDate.month currentDate.day %}",
		"{% trans "Návrhy skupinou podpořené" %}"
	);
	
	createGrid(
		"#nay",
		"#nay-pager",
		"{% url json.views.get_group_nay group.slug,currentDate.year,currentDate.month,currentDate.day %}",
		"{% trans "Návrhy skupinou zamítnuté" %}"
	);

	createGrid(
		"#refrain",
		"#refrain-pager",
		"{% url json.views.get_group_refrains group.slug,currentDate.year,currentDate.month,currentDate.day %}",
		"{% trans "Skupina se zdržela hlasování" %}"
	);

	createGrid(
		"#absences",
		"#absences-pager",
		"{% url json.views.get_group_absences group.slug,currentDate.year,currentDate.month,currentDate.day %}",
		"{% trans "Skupina se nezúčastnila hlasování" %}"
	);

	{% if peerGroupTypeIndex %}
		$("#groupTypeDay")[0].selectedIndex = {{ peerGroupTypeIndex }};
		groupTypeChanged("groupTypeDay");
		$.scrollTo('#loyalChartTermControl', 800);
	{% endif %}

	{% if peerGroupIndex %}
		$("#groupNamesDay")[0].selectedIndex = {{ peerGroupIndex }};
		groupNameChanged("groupNamesDay");
		$.scrollTo('#loyalChartTermControl', 800);
	{% endif %}

	{% if peerTermGroupTypeIndex %}
		$("#groupTypeTerm")[0].selectedIndex = {{ peerTermGroupTypeIndex }};
		groupTypeChanged("groupTypeTerm");
		$.scrollTo('#loyalChartTermControl', 800);
	{% endif %}

	{% if peerTermGroupIndex %}
		$("#groupNamesTerm")[0].selectedIndex = {{ peerTermGroupIndex }};
		groupNameChanged("groupNamesTerm");
		$.scrollTo('#loyalChartTermControl', 800);
	{% endif %}
});
{% endblock %}

{% block left-sidebar %}
	<div class="ui-widget">
		<div class="ui-widget-header">
			<h1>{% trans "Kalendář hlasování" %}</h1>
		</div>
		<div class="ui-widget-content">
			<div class="container">
				{% url json.views.get_meetings_in_month currentDate.year currentDate.month as events %}
				{% url psp.views.show_day_polls currentDate.year currentDate.month currentDate.day as eventDetails %}
				{% datepicker "meetingPicker" events eventDetails currentDate.year currentDate.month dateStart dateEnd onSelect="meetingPickerSelect" %}
			</div>
		</div>
	</div>
	
	<ul class="termList">
		{% for t in terms %}
			<li>{{ t|safe }}</li>
		{% endfor %}
	</ul>
{% endblock %}

{% block content %}
<div class="ui-widget">
	<div class="ui-widget-header">
		<h1>{{ group.name }} {{ term.getStart }} - {{ term.getEnd }}</h1>
	</div>
	<div class="ui-widget-content">
		{% if partyPie %}
		<div class="left">
		{% endif %}
			<p> {% blocktrans %}
				Ve skupině se schází celkem {{ membersTotal }} poslanců.
				Průměrný věk celé skupiny dosáhl {{ avgAge }} let na začátku
				funkčního období. 
				{% endblocktrans %}
			{% if partyPie %}
				{% blocktrans %}
					Graf vpravo zachycuje partajní složení skupiny.
				{% endblocktrans %}
			{% endif %}
			</p>
		{% if partyPie %}
		</div> <!-- left -->
		<div class="right">
			<p>
				{{ partyPie.img|safe }}
			</p>
		</div>
		<div class="clear"></div>
		{% endif %}

		<p>
			<table id="mp-list" class="scroll" cellpadding="0" cellspacing="0">
			</table>
			<div id="mp-pager" class="scroll" style="text-align:center;">
			</div>
		</p>
	</div>
</div>

<div class="ui-widget">
	<div class="ui-widget-header">
		<h2>{% trans "Naše absence a shoda s jinou skupinou za celé období" %}</h2>
	</div>
	<div class="ui-widget-content">
		<div class="left">
			{% trans "Graf vpravo bonzuje jak moc naše skupina na hlasování kašlala v obodbí" %}
			{{ term.getStart }} - {{ term.getEnd }}.
		</div>
		<div class="right">
			{{ groupPresenceChart.img|safe }}
		</div>

		<div class="clear"><p></p></div>
		<p>	{% blocktrans %}
			Aby se vám zobrazil koláč (graf) znázorňující shodu hlasování
			{% endblocktrans %}
			{% ifequal group.type "KLUB" %}
				{{ group.getPartyName }}
			{% else %}
				{{ group.name }}
			{% endifequal %}
			{% blocktrans %}
			s jinou (srovnávací) skupinou, musíte nejprve tuto skupinu
			vybrat. Skupinu vyberete z nabídky schované v roletkách dole. 
			{% endblocktrans %}
		</p>
		<p>	
			{% trans "Koláč (graf) znázorňující shodu/loajalitu skupiny" %}
			{% ifequal group.type "KLUB" %}
				{{ group.getPartyName }}
			{% else %}
				{{ group.name }}
			{% endifequal %}
			{% blocktrans %}
			s vybranou skupinou je vypočten podle následujících pravidel:
			<ol>
				<li>
					Seberou se výsledky hlasováni v daném období (den/volební období) pro 
					{% endblocktrans %}
					{% ifequal group.type "KLUB" %}
						{{ group.getPartyName }},
					{% else %}
						{{ group.name }},
					{% endifequal %}
				</li>
				<li> {% blocktrans %}
					stejně tak se vyberou výsledky hlasování pro vybranou skupinu,
				</li>
				<li>
					výsledky získané v krocích (1) a (2) se porovnají, tím spočteme hlasování,
					kdy obě skupiny hlasovaly stejně a kdy skupiny hlasovaly různě.
				</li>
			</ol>
			{% endblocktrans %}
		</p>
		<p>
			Výsledek hlasování celé skupiny se spočítá jako maximum z hlasů pro/proti/zdržel/nepřítomen,
			odevzdaných v rámci celé skupiny. Dojde-li k rovnosti hlasů (např. 5xPro, 5xProti) bude výsledek
			hlasování skupiny proti. Rovnost hlasů ve skupině je velmi vzácný jev, takže tato implementační
			nepřesnost celkový výsledek nezkreslí.
		</p>
		<div id="loyalChartTermControl">
			<div class="left">
				<div id="loyalChartGroupTerm" class="pieChartHeight">
				</div>
				<div class="groupSelect">
				<select name="groupTypesTerm" id="groupTypeTerm" onChange="groupTypeChanged(this.id)">
				{% for groupType in groupsByType.keys %}
					<option value="{{ groupType|slugify }}">{{ groupType|title }}</option>
				{% endfor %}
				</select>
				</div>
			</div>
			<div class="right">
				<div id="partyPieChartTerm" class="pieChartHeight">
				</div>
				<div class="groupSelect">
				<select name="groupNamesTerm" id="groupNamesTerm" onChange="groupNameChanged(this.id)">
					<option value="">{% trans "Vyberte skupinu" %}</option>
				{% for group in groupsByType.KLUB %}
					<option value="{{ group.id }}">{{ group.name|truncatewords:3 }}</option>
				{% endfor %}
				</select>
				</div>
				<p>
					<a href="{% url psp.views.show_group_day group.slug,currentDate.year,currentDate.month,currentDate.day %}" class="ctrl-link">link</a>
				</p>
			</div>
			<div class="clear"></div>	
		</div>
	</div>
</div>
<div class="ui-widget">
	<div class="ui-widget-header">
		<h2>{% trans "Naše hlasování" %} <span id="pollDate">{{ currentDate|date:"Y m d" }}</span></h2>
	</div>
	<div class="ui-widget-content">
		<div class="left">
			<div id="groupDayStatChart">
				{% with groupStats.getResultChart as chart %}
				{{ chart.img|safe }}
				{% endwith %}
			</div>
			<div id="dateNav">
				<script type="text/javascript">
					{% comment %}
						Same pattern we've already seen in switchDate() function
						
						Also don't forget to update meetingPicker with new date
						(the 'true' argument in switchDate()). 
					 {% endcomment %}
					{% url json.views.get_date_data_group_json group.slug currentDate.year currentDate.month currentDate.day  as baseUrl %}
					var baseUrl = '{{ baseUrl }}'.replace(/\/\d{4}\/\d{1,2}\/\d{1,2}\//g,'');
				</script>
				<div class="left">
					{% if prevDate %}
						<a href="#void" onClick="switchDate(baseUrl + '/' + prevDate, prevDate, true)" id="prevDay">
					{% else %}
						<a href="#void" onClick="switchDate(baseUrl + '/' + prevDate, prevDate, true)" id="prevDay" class="slideDefaultHidden">
					{% endif %}
						<span class="ui-icon ui-icon-arrowthick-1-w"></span>
						<span id="prevDate">{{ prevDate|date:"Y m d" }}</span>
					</a>
				</div>
				<div class="right">
					{% if nextDate %}
						<a href="#void" onClick="switchDate(baseUrl + '/' + nextDate, nextDate, true)" id="nextDay">
					{% else %}
						<a href="#void" onClick="switchDate(baseUrl + '/' + nextDate, nextDate, true)" id="nextDay" class="slideDefaultHidden">
					{% endif %}
						<span class="ui-icon ui-icon-arrowthick-1-e"></span>
						<span id="nextDate">{{ nextDate|date:"Y m d" }}</span>
					</a>
				</div>
			</div>
		</div>
		<div class="right">
		{% with groupStats.absences as groupAbsences %}
		{% with groupStats.votesAye as groupAye %}
		{% with groupStats.votesNay as groupNay %}
		{% with groupStats.votesRefrain as groupRefrains %}
		<p> {% blocktrans %}
			Tento den proběhlo <span id="totalDayPolls">{{ totalDayPolls }} </span> hlasování.
			<span id="acceptedProposals">{{ acceptedProposals }} </span> návrhů bylo přijato,
			zatímco <span id="refusedProposals">{{ refusedProposals }} </span> jich bylo zamítnuto.
			Naše skupina se nezúčastnila <span id="groupAbsences">{{ groupAbsences }}</span> hlasování.
			<span id="groupAye"> {{ groupAye  }}</span>x jsme hlasovali pro,
			<span id="groupNay">{{ groupNay }}</span>x proti a
			<span id="groupRefrains"> {{ groupRefrains }}</span>x jsme se zdrželi hlasování.
			{% endblocktrans %}
		</p>
		{% endwith %}
		{% endwith %}
		{% endwith %}
		{% endwith %}
		<p>
			<a href="{% url psp.views.show_group_day group.slug,currentDate.year,currentDate.month,currentDate.day %}" class="ctrl-link">link</a>
		</p>
		</div>
		<div class="clear"></div>
	</div>
</div>

<div class="ui-widget">
	<div class="ui-widget-header">
		<h2>{% trans "Shoda s jinou skupinou za den" %}</h2>
	</div>
	<div class="ui-widget-content">
		<div id="loyalChartDayControl">
			<div class="left">
				<div id="loyalChartDayGroup" class="pieChartHeight">
				</div>
				<div class="groupSelect">
				<select name="groupTypesDay" id="groupTypeDay" onChange="groupTypeChanged(this.id)">
				{% for groupType in groupsByType %}
					<option value="{{ groupType|slugify }}">{{ groupType|title }}</option>
				{% endfor %}
				</select>
				</div>
			</div>
			<div class="right">
				<div id="partyPieChartDay" class="pieChartHeight">
				</div>
				<div class="groupSelect">
				<select name="groupNamesDay" id="groupNamesDay" onChange="groupNameChanged(this.id)">
					<option value="">{% trans "Vyberte skupinu" %}</option>
				{% for group in groupsByType.KLUB %}
					<option value="{{ group.id }}">{{ group.name|truncatewords:3 }}</option>
				{% endfor %}
				</select>
				</div>
				<p>
					<a href="{% url psp.views.show_group_day group.slug,currentDate.year,currentDate.month,currentDate.day %}" class="ctrl-link">link</a>
				</p>
			</div>
			<div class="clear"></div>
		</div>
	</div>
</div>

<div class="ui-widget">
	<div class="ui-widget-header">
		<h2>{% trans "Detailní přehled" %}</h2>
	</div>
	<div class="ui-widget-content">
		<p>
		<input type="checkbox" id="filterProcedural" onclick="filterProcedural(this.checked)">
			{% trans "Skryj procedurální hlasování" %}  <br/> 
		</p>
			<table id="aye" class="scroll" cellpadding="0" cellspacing="0">
			</table>
			<div id="aye-pager" class="scroll" style="text-align:center;">
			</div>
		<p>
		</p>
			<table id="nay" class="scroll" cellpadding="0" cellspacing="0"> 
			</table>
			<div id="nay-pager" class="scroll" style="text-align:center;">
			</div>
		<p>
		</p>
			<table id="refrain" class="scroll" cellpadding="0" cellspacing="0"> 
			</table>
			<div id="refrain-pager" class="scroll" style="text-align:center;">
			</div>
		<p>
		</p>
			<table id="absences" class="scroll" cellpadding="0" cellspacing="0"> 
			</table>
			<div id="absences-pager" class="scroll" style="text-align:center;">
			</div>
		</p>
	</div>
</div>

{% endblock %}
